<template>
  <div class="LoginForm">
    <div class="phone">
      <span>手机号：</span>
      <el-input v-model="phone" placeholder="请输入手机号"></el-input>
    </div>
    <div class="password">
      <span>密码：</span>
      <el-input v-model="password" placeholder="请输入密码"></el-input>
    </div>
    <el-button type="primary" @click="login" style="width: 100%; margin: 10px">
      登录
    </el-button>
  </div>
</template>


<script>
export default {
  name: "LoginCart",
  data() {
    return {
      phone: "",
      password: "",
      user:""
    };
  },
  computed:{
    
  }
  ,
  methods: {
    login() {
      let _this = this;
      this.$axios({
        url: "/user/login",
        method: "post",
        data: { phone: _this.phone, password: _this.password },
      }).then(function (resp) {
        if(resp.data == ""){
          alert("登录失败，请重新输入")
        }else{
          alert("登录成功")
          _this.user = resp.data;
          window.localStorage.setItem('user',JSON.stringify(_this.user));
          _this.$store.commit('setUser',_this.user)
          location.reload();
        }
      });
    },
  },
};
</script>


<style scoped>
.phone {
  display: flex;
  margin: 10px;
}

.phone span {
  width: 15%;
}

.password {
  display: flex;
  margin: 10px;
}

.password span {
  width: 15%;
}
</style>